#include <algorithm>
#include <iostream>
#include <stack>
using namespace std;

const int kMaxN = 1e5 + 10;
const int kInf = 1e9;

pair<int, int> line[kMaxN];

int main() {
  freopen("crossings.in", "r", stdin);
  freopen("crossings.out", "w", stdout);
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> line[i].first >> line[i].second;
  }
  sort(line, line + n);

  int now_maxx = -kInf;
  stack<int> sta;

  for (int i = 0; i < n; i++) {
    if (line[i].second > now_maxx) {
      now_maxx = line[i].second;
      sta.push(line[i].second);
    }
    while (!sta.empty() && sta.top() > line[i].second) {
      sta.pop();
    }
  }
  cout << sta.size() << "\n";
  return 0;
}